package com.jiugang.cardump.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.jiugang.cardump.bean.InformationBean;
import com.jiugang.cardump.constant.StatusCodeConstant;
import com.jiugang.cardump.entity.User;
import com.jiugang.cardump.exception.SystemExceptionV110;
import com.jiugang.cardump.mapper.UserMapper;
import com.jiugang.cardump.result.ResultInfoV110;
import com.jiugang.cardump.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2021-08-19
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * @param account 账号
     * @param password 密码
     * @return ResultInfoV110
     * @Description 登录接口
     */
    @Override
    public ResultInfoV110 login(String account, String password) {
        log.info("UserServiceImpl的login,参数account为"+account+",参数password为"+password);
        Integer count = userMapper.login(account, password);
        //登录成功
        if(count == 1){
            return ResultInfoV110.success("欢迎");
        }
        //登录失败
        throw new SystemExceptionV110(InformationBean.setInformationBean(StatusCodeConstant.W001,"账号或密码"));
    }
}
